<template lang="pug">
  .videoPage
    div.table-empty
      s-table(
        ref="table"
        :reqUrl="tableObj.url"
        reqMethod="get"
        :column="tableObj.column"
        :filterProps="{ showBtns: false, fields: [] }"
      )
        .table-operator(slot="table-operator")
          //- el-button(size="large" round plain @click="templateDown()") 发卡
          el-button.gradientVertical(size="large" round @click="addHandle()") 新增
        template(slot="action" slot-scope="text, scope")
          el-link(@click="pushNotification(scope.id)" type="success") 消息推送
          el-link(@click="deleteHandle(scope.id)" type="primary") 删除
    add-drawer(:visible.sync="addObj.visible" @getList="() => refreshTable(true)")
</template>
<script>
import AddDrawer from './addDrawer'
import { column } from './config'
import { api, delAttendance, pushNotification } from './api'

export default {
  components: {
    AddDrawer
  },
  data () {
    return {
      tableObj: {
        url: api.list,
        column
      },
      addObj: {
        visible: false,
        id: ''
      }
    }
  },
  methods: {
    refreshTable (flag = false) {
      this.$refs.table.refresh(flag)
    },
    addHandle (id = '') {
      this.addObj = {
        visible: true,
        id
      }
    },
    deleteHandle (id) {
      this.$confirm('确认删除吗？')
        .then((_) => {
          console.log(_)
          console.log(_ === 'confirm')
          if (_ === 'confirm') {
            console.log(_ === 'confirm')
            delAttendance({ id: id }).then(() => {
              this.$message.success('删除成功')
              this.refreshTable()
            })
          }
        })
        .catch((_) => {})
    },

    pushNotification (id) {
      pushNotification({ checkerId: id })
        .then(() => {
          this.$message.success('推送成功')
        })
        .catch(() => {
          this.$message.error('推送失败')
        })
    }
  }
}
</script>
